#include "PrecompiledHeader.h"
#include "PointLight.h"

/*--------------------------------------------------------------------------*/

PointLight::PointLight(const NodeCreation& nc) :
	ILightSourceObject(nc)
{
	AssertModule(g_Material);

	RenderTaskDesc desc;
	desc.m_material = g_Material->GetMaterial("mat_pointlight");
	desc.m_argument = 0;
	desc.m_flags = ERenderTaskFlag::LightSource | ERenderTaskFlag::SortByDist | ERenderTaskFlag::Transparent;
	desc.m_priority = 0;
	desc.m_object = this;

	this->AddRenderTask(desc);
}

/*--------------------------------------------------------------------------*/

PointLight::~PointLight()
{

}

/*--------------------------------------------------------------------------*/

void PointLight::DrawLightVolume()
{
#ifdef VL_RENDER_STATISTICS
	g_Hud->GetStatisticsManager()->IncrementStatistic("PointLight");
#endif
	ROpenGL::BindVertexArray(ROpenGL::GetCubeVao());
	ROpenGL::DrawVertexArray();
}

/*--------------------------------------------------------------------------*/

void PointLight::OnPreRender(const RenderTask* renderTask)
{
	glm::vec3 diff(this->GetDiffuse().r, this->GetDiffuse().g, this->GetDiffuse().b);
	float r = this->GetRadius();

	g_Material->SetLightProperties(&this->GetRelativePosition(),
	                               &diff,
	                               NULL,
	                               &r,
	                               NULL,
	                               NULL);
}

/*--------------------------------------------------------------------------*/
